package com.jz.control;



import com.rjxy.code.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @ClassName VerifyCodeServlet
 * @Description 获取验证码及输出验证码图片
 * @Author MR_Liu
 * @Date 2021/7/22 0022 10:26
 * @Version 1.0
 */
@WebServlet("/code")
public class VerifyCodeServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取验证码
        ValidateCode vc = new ValidateCode();
        String code = vc.getCode();
        //将验证码存入session-->登录校验的时候使用
        HttpSession session = req.getSession();
        session.setAttribute("code",code);
        //输出验证码图片
        vc.write(resp.getOutputStream());
        System.out.println(code);
    }
}
